"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const https_1 = __importDefault(require("https"));
const Config_1 = require("../models/Config");
async function default_1(call) {
    const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${Config_1.Config.wx_appid}&secret=${Config_1.Config.wx_secret}&js_code=${call.req.code}&grant_type=authorization_code`;
    https_1.default.get(url, res => {
        res.on('data', data => {
            const obj = JSON.parse(data);
            if (obj.errcode) {
                call.error('登陆失败', obj.errmsg);
                return;
            }
            call.succ({
                openid: obj.openid,
                session_key: obj.session_key
            });
        }).on('error', err => {
            call.error('登录失败', err);
            return;
        });
    });
}
exports.default = default_1;
